#include <stdio.h>
#include <string.h>
#include <sys/time.h>

struct timeval begin_time;
struct timeval begin_time2;

int a_time;
int b_time;

void set_begin_time(struct timeval *begin_time)
{
    gettimeofday(begin_time, NULL);
}

//return time in microsecond
int get_time_interval(struct timeval *begin_time)
{
    struct timeval end_time;
    gettimeofday(&end_time, NULL);
    return (1000000 * (end_time.tv_sec - begin_time->tv_sec) + end_time.tv_usec - begin_time->tv_usec);
}

int a()
{
    char a[1000] = { 0 };
    char b[1000] = { 0 };

set_begin_time(&begin_time2);

    memset(a, 0, sizeof(a));
    memset(b, 0, sizeof(b));

    strcpy(a, "this is a good day!");
    strcpy(b, "今天不错!");
a_time = get_time_interval(&begin_time2);

    return 0;
}

int b()
{
    set_begin_time(&begin_time);
    a();
    b_time = get_time_interval(&begin_time);
}

int main(int argc, char **argv)
{
    b();
    printf("a_time:[%d],b_time:[%d]\n", a_time, b_time);

	return 0;
}
